home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 412_01 / demos / demo1.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-28  |  2.1 KB  |  75 lines

  1. #include <stdio.h>
  2. #include "graph.h"
  3.  
  4. /*              DEMO1
  5.  
  6.     In this example problem a simple 15-puzzle will be solved. The
  7.     start state has the empty tile in the lower right corner (3,3).
  8.     Operators are up, down, right and left. The goalstate has the empty
  9.     tile in its upperleft corner (0,0). For the solution of this simple
  10.     problem only the coordinates of the empty tile are required. The
  11.     actual configuration of the board is considered unimportant here.
  12.   
  13. */
  14.  
  15.  
  16.  
  17. /*                    PNODE_
  18.  
  19.     Class PNODE_ defines the objects used in this problem. A PNODE_ object
  20.     represents a single board configuration as a node in a tree search or
  21.     as a state in a state space. 
  22.  
  23. */
  24.  
  25. enum OP_USED_             // defines operators used to get to current state
  26. {
  27.     none_used,            // start state
  28.     left_used,
  29.     right_used,
  30.     up_used,
  31.     down_used
  32. };
  33.  
  34. class PNODE_ : public NODE_
  35. {
  36.     public:
  37.         PNODE_(OP_USED_ operator_used, int empty_x, int empty_y);
  38.         int get_x() const;                   // get x-coordinate of empty tile
  39.         int get_y() const;                   // get y-coordinate of empty tile
  40.  
  41. // implementation of virtual functions
  42.         int equal(const VOBJECT_ &) const;   // compare two configurations
  43.         void display() const;                // display configuration
  44.         NODE_ *do_operator(int) const;       // apply operator n
  45.     private:
  46.         PNODE_
  47.             *do_left() const,                // called by do_operator()
  48.             *do_right() const,
  49.             *do_up() const,
  50.             *do_down() const;
  51.         OP_USED_
  52.             operator_used;            // operator used to get to current state
  53.         int
  54.             x,
  55.             y;                        // coordinates of empty tile
  56. };
  57.  
  58.  
  59.  
  60. /*                     PUZZLE_
  61.  
  62.     Class PUZZLE_ determines which search algorithm is to be used,
  63.     in this case: a depth first graph search.
  64.  
  65. */
  66.  
  67. class PUZZLE_ : public DEPTH_GRAPH_
  68. {
  69.     public:
  70.         PUZZLE_(PNODE_ *start, PNODE_ *goal);
  71. };
  72.  
  73.  
  74.  
  75.